﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TruckWatch.Cloud.Models;
using TruckWatch.Cloud.DAL;

namespace TruckWatch.Cloud.BusinessLogic
{
    public class ServiceBL
    {

        public static void UpdateLocation(DriverCredential credential, TripPointNEF tripPoint)
        {
            // Check Credential
            DriverNEF driver = SecurityBL.CheckDriverCredentials(credential);

            if (tripPoint.Latitude == 0)
                throw new ValidationException("Latitude is Required");
            if (tripPoint.Longitude == 0)
                throw new ValidationException("Longitude is Required");

            // DriverId
            tripPoint.DriverId = driver.Id;

            // ArriveDate
            tripPoint.ArriveDate = DateTime.UtcNow;

            // TripId
            tripPoint.TripId = TripBL.GetTripIdForCurrentDateTime(driver.Id);

            // Update
            TripPointDAL.UpdateLocation(tripPoint);
        }

        public static void UpdateStatus(DriverCredential credential, TripStatusNEF tripStatus)
        {
            // Check Credential
            DriverNEF driver = SecurityBL.CheckDriverCredentials(credential);

            // Validate

            // DriverId
            tripStatus.DriverId = driver.Id;

            // StatusDate
            tripStatus.StatusDate = DateTime.UtcNow;

            // TripId
            tripStatus.TripId = TripBL.GetTripIdForCurrentDateTime(driver.Id);

            // Update
            TripStatusDAL.UpdateTripStatus(tripStatus);
        }

    }
}
